package com.minyifang.wcspf.work.ui.home.presenter;

import com.minyifang.wcspf.common.base.BasePresenter;
import com.minyifang.wcspf.common.config.network.Constants;
import com.minyifang.wcspf.common.config.network.RetrofitHelper;
import com.minyifang.wcspf.common.config.user.UserManager;
import com.minyifang.wcspf.work.model.HttpRespond;
import com.minyifang.wcspf.work.ui.home.model.HomePage1Bean;
import com.minyifang.wcspf.work.ui.home.model.RecommendGoodsBean;
import com.minyifang.wcspf.work.ui.home.view.HomePage1View;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.functions.Consumer;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by LuoYaWei on 2018/7/10.
 */
public class HomePage1Presenter extends BasePresenter<HomePage1View> {
    public void getData() {
        JSONObject jsonData = Constants.getJsonData(new HashMap<>(), UserManager.getInstance().getToken());
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonData.toString());
        addTask(RetrofitHelper.getInstance().getService().getHomeData(requestBody), homePage1BeanHttpRespond -> getView().showHomeData(homePage1BeanHttpRespond));

    }

    public void getRecommendGoodsList(int page, int limit) {
        Map<String, Object> map = new HashMap<>();
        map.put("page", page);
        map.put("limit", limit);
        JSONObject jsonData = Constants.getJsonData(map, UserManager.getInstance().getToken());
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonData.toString());
        addTask(RetrofitHelper.getInstance().getService().getRecommendGoodsList(requestBody), respond -> getView().showRecommendGoodsList(respond));
    }

}
